﻿using Common.Communal;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Api.Read.Applications.Commands.Users;
using System.DTO;

namespace System.Api.Read.Controllers
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        ILogger<UserController> logger;

        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        public UserController(IMediator mediator, ILogger<UserController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public Task<ApiResult<UserDTO>> Login(UserLoginCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 用户分页查询
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<UserRoleDTO>>> GetUser([FromQuery] UsersQueryCommand command)
        {
            logger.LogInformation("开始调用用户分页查询接口");
            return mediator.Send(command);
        }
        //public static  SqlSugarClient Carry(IConfiguration configuration)
        //{
        //    var connectionString = configuration.GetValue<string>("conn");
        //    SqlSugarClient sqlSugar=new SqlSugarClient(new ConnectionConfig()
        //    {
        //        ConnectionString = connectionString,
        //        DbType = DbType.MySql,
        //        IsAutoCloseConnection = true
        //    });
        //}
    }
}
